<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/back/welcome">首页</a>
            <a href="#">新闻管理</a>
            <a>
              <cite>新闻发布</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" action="" method="post">
            <div class="layui-form-item">
                <label for="newsTitle" class="layui-form-label">
                    <span class="x-red">*</span>新闻标题
                </label>
                <div class="layui-input-block"  style="width: 900px !important;">
                    <input type="text" id="newsTitle" name="newsTitle" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="endTime" class="layui-form-label">截止时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" readonly  autocomplete="off" placeholder="截止开始日期" id="endTime">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="newsOutline" class="layui-form-label">新闻摘要</label>
                <div class="layui-input-block"  style="width: 900px !important;">
                    <textarea placeholder="请输入内容" id="newsOutline" name="newsOutline" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="newsContent" class="layui-form-label">
                    <span class="x-red">*</span>新闻内容
                </label>
                <div class="layui-input-inline" style="width: 900px !important;">
                    <textarea id="newsContent" name="newsContent" style="display: none;"></textarea>
                </div>
                <div class="layui-form-mid layui-word-aux">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    确认保存
                </button>
            </div>
        </form>
    </div>
</div>
<script th:inline="none">
    layui.use(['form','jquery','tool','validate','layedit','laydate'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var tool = layui.tool;
        var laydate = layui.laydate;
        var validate = layui.validate;
        var layedit = layui.layedit;
        init_form();

        var newsContent = layedit.build('newsContent',{
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线
                ,'|' //分割线
                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'link' //超链接
                ,'unlink' //清除链接
                ,'face' //表情
                ,'image' //插入图片
                ,'code' //插入代码
                // ,'preview' //预览（暂未开发）
            ]
            ,height: 500 //设置编辑器高度
            ,uploadImage: {
                url:'/back/upload/singleFileUpload'
                ,type:'post'
            }
        });


        function init_form() {
            laydate.render({
                elem: '#endTime'
                ,type: 'datetime'
            });
        }
        form.on('submit(add)', function(data){
            data.field.newsContent = layedit.getContent(newsContent);
            data.field.endTimeStr = $("#endTime").val().trim();
            var res = tool.submit('/back/news/add',data.field);
            if(res.code == return_200){
                layer.msg(res.msg, {
                        icon: msg.success,
                        time: 2000
                    },
                    function(){
                        callBack();
                    }
                );
            }else {
                layer.msg(res.msg, {
                        icon: msg.error,
                        time: 2000
                    },
                    function(){
                        callBack();
                    }
                );
            }
            return false;
        });

        /**
         * 回调函数
         */
        function callBack() {
            location.reload()
        }

    });
</script>
</body>
</html>